//
//  MoreActivityTableViewCell.m
//  LuckyRadio
//
//  Created by Mr、J on 15/11/25.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "MoreActivityTableViewCell.h"
#import <UIImageView+WebCache.h>

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define WIDTH_PRO(X) (X)*(SCREEN_WIDTH/375)

#define HEIGHT_PRO(Y) (Y)*(SCREEN_HEIGHT/667)
@implementation MoreActivityTableViewCell
- (void)dealloc
{
    [_image release];
    [_titleLabel release];
    [_tagLabel release];
    [_moreActivityModel release];
    [_timeLabel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews
{
    self.image = [[UIImageView alloc] init];
    self.image.image = [UIImage imageNamed:@"online_default_big_logo"];
    [self.contentView addSubview:self.image];
    [_image release];
    
    self.tagImage = [[UIImageView alloc] init];
    self.tagImage.image = [UIImage imageNamed:@"image.jpg"];
    [self.image addSubview:self.tagImage];
    [_tagImage release];
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    self.tagLabel = [[UILabel alloc] init];
    self.tagLabel.textColor = [UIColor grayColor];
    self.tagLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.tagLabel];
    [_tagLabel release];
    
    self.timeLabel = [[UILabel alloc] init];
    self.timeLabel.textColor = [UIColor grayColor];
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.timeLabel];
    [_timeLabel release];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.image.frame = CGRectMake(WIDTH_PRO(10), HEIGHT_PRO(10), SCREEN_WIDTH - WIDTH_PRO(20), HEIGHT_PRO(80));
    
    self.tagImage.frame = CGRectMake(0, HEIGHT_PRO(5), WIDTH_PRO(50), HEIGHT_PRO(20));
    self.titleLabel.frame = CGRectMake(WIDTH_PRO(10), self.image.frame.size.height + HEIGHT_PRO(20), SCREEN_WIDTH - WIDTH_PRO(130), HEIGHT_PRO(20));
    self.tagLabel.frame = CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height, SCREEN_WIDTH - WIDTH_PRO(20), HEIGHT_PRO(20));
    self.timeLabel.frame = CGRectMake(SCREEN_WIDTH - WIDTH_PRO(110), self.titleLabel.frame.origin.y , WIDTH_PRO(100), HEIGHT_PRO(20));
}

-(void)setMoreActivityModel:(MoreActivityModel *)moreActivityModel{
    if (_moreActivityModel != moreActivityModel) {
        [_moreActivityModel release];
        _moreActivityModel = [moreActivityModel retain];
    }
    
    [self.image sd_setImageWithURL:[NSURL URLWithString:moreActivityModel.picUrl] placeholderImage:[UIImage imageNamed:@"Read_zhanwei"]];
    [self.tagImage sd_setImageWithURL:[NSURL URLWithString:moreActivityModel.tagUrl] placeholderImage:[UIImage imageNamed:@"Read_zhanwei"]];
    self.titleLabel.text = moreActivityModel.name;
    self.tagLabel.text = moreActivityModel.desc;
    
    
    NSTimeInterval time = [moreActivityModel.startTime doubleValue] / 1000;
    
    NSLog(@"wrwrw%.0f", time);
    
    NSDate *detailDate = [NSDate dateWithTimeIntervalSince1970:time];
    
    NSLog(@"date:%@", [detailDate description]);
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    [dateFormatter setDateFormat:@"yyyy.MM.dd"];
    
    NSString *currentDateStr = [dateFormatter stringFromDate:detailDate];
    
    NSLog(@"sssssss===%@", currentDateStr);
    
    
    NSTimeInterval time2 = [moreActivityModel.endTime doubleValue] / 1000;
    
    NSLog(@"wrwrw%.0f", time);
    
    NSDate *detailDate2 = [NSDate dateWithTimeIntervalSince1970:time2];
    
    NSLog(@"date:%@", [detailDate description]);
    
    NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
    
    [dateFormatter2 setDateFormat:@"MM.dd"];
    
    NSString *currentDateStr2 = [dateFormatter2 stringFromDate:detailDate2];
    
    NSLog(@"sssssss===%@", currentDateStr);
    
    self.timeLabel.text =[NSString stringWithFormat:@"%@ - %@", currentDateStr, currentDateStr2];
    
    

    
    
    
}

+(MoreActivityTableViewCell *)moreActivityTableViewCellWith:(UITableView *)tableView
{
    static NSString *cellIdentify = @"cellIdentify";
    MoreActivityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if (!cell) {
        cell = [[MoreActivityTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify];
    }
    return cell;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
